﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Common;
using System.Data;

/// <summary>
/// Summary description for StudentDao
/// </summary>
public class StudentDao : BasicDaoSql
{
    private string SQL_INSERT_STUDENT_DTO = "Insert into Student (StudentId, Name, Age, Surname)" +
        " values(@StudentId, @Name, @Age, @Surname)";

    public void insertStudentDto(StudentDto studentDto)
    {
        DbConnection dbConnection = null;
        DbCommand dbCommand = null;
        dbConnection = getDatabaseConnection();
        dbCommand = dbConnection.CreateCommand();
        dbCommand.CommandText = SQL_INSERT_STUDENT_DTO;
        dbCommand.CommandType = CommandType.Text;
        DbParameter[] para = CreateDBParameter(dbCommand, 4);
        para[0].ParameterName = "StudentId";
        para[0].Value = studentDto.StudentId;
        para[1].ParameterName = "Name";
        para[1].Value = studentDto.Name;
        para[2].ParameterName = "Age";
        para[2].Value = studentDto.Age;
        para[3].ParameterName = "Surname";
        para[3].Value = studentDto.Surname;
        dbCommand.Parameters.AddRange(para);
        dbCommand.ExecuteNonQuery();
    }
}
